import { View } from "../../../mvc/core/View";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ClockManager } from "../../manager/ClockManager";
import { Cache } from "../../cache/Cache";
import { PublicMessageConfig } from "../../resource/PublicMessageConfig";
import { EArenaProcess } from "../../../../Message/Public/EArenaProcess";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DateTipSp } from "./DateTipSp";
import { KingwarTimeProgress } from "./KingwarTimeProgress";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class KingWarTimePanel
    
    export  class KingWarTimePanel extends View
    {
        constructor()
        {
            super();
            this._dateTipArr = [];
            this.initView();
            return;
        }

        protected onKingRewardClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            MsgManager.showRollTipsMsg(Language.getString(70442));
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._sbmArrowII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_arrow2);
            this._sbmArrowIII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_arrow3);
            this._sbmArrowIV.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_arrow4);
            this._sbmArrowV.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_downArrow);
            this._sbmMid2.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_close);
            this._sbmMid3.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_close);
            this._sbmMid4.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_close);
            this._sbmUp.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_noRise);
            return;
        }

        protected onTxClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._skipDecTx:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarSkipTab, 0));
                    break;
                }
                case this._checkRuleTx:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarRuleDescToTabBar, 0));
                    break;
                }
            }
            return;
        }

        public updateInfo(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=NaN;
            var loc9=NaN;
            var loc10=NaN;
            var loc11=NaN;
            var loc12=NaN;
            var loc13=NaN;
            var loc14=NaN;
            var loc15=NaN;
            this._nowData = ClockManager.instance.nowDate;
            this.str = Language.getString(70406) + "：" + this._nowData.getFullYear() + "." + (this._nowData.getMonth() + 1) + "." + this._nowData.getDate();
            this._curTimeTx.text = this.str;
            if (Cache.instance.kingwar.sArenaInfo) 
            {
                this._myProcess = Cache.instance.kingwar.sArenaInfo.myProcess;
                this._syProcess = Cache.instance.kingwar.sArenaInfo.process;
                this._isOpen = Cache.instance.kingwar.sArenaInfo.isOpen;
                this._txCurProcess.text = PublicMessageConfig.instance.getArenaProcess(Cache.instance.kingwar.sArenaInfo.process);
                loc2 = 0;
                while (loc2 < this._dateTipArr.length) 
                {
                    loc1 = this._dateTipArr[loc2];
                    loc1.updateInfo(Cache.instance.kingwar.getDateTipsArr()[loc2]);
                    ++loc2;
                }
                loc3 = this._syProcess;
                if (loc3 < 0) 
                {
                    loc3 = 0;
                }
                this._progressBar.setValue(Cache.instance.kingwar.changeType(loc3) * 33, 100);
                this.updateImages();
                if (loc4 = Cache.instance.kingwar.sArenaInfo.processDt[EArenaProcess._EArenaElimination1]) 
                {
                    loc8 = loc4.getMonth() + 1;
                    loc9 = loc4.getDate();
                    this._txII.htmlText = Language.getStringByParam(70419, loc8, loc9, loc8, loc9 + 1);
                }
                else 
                {
                    this._txII.htmlText;
                }
                if (loc5 = Cache.instance.kingwar.sArenaInfo.processDt[EArenaProcess._EArenaGroupMatch1]) 
                {
                    loc10 = loc5.getMonth() + 1;
                    loc11 = loc5.getDate();
                    this._txIII.htmlText = Language.getStringByParam(70420, loc10, loc11);
                }
                else 
                {
                    this._txIII.htmlText;
                }
                loc6 = Cache.instance.kingwar.sArenaInfo.processDt[EArenaProcess._EArenaFinalMatch1];
                loc7 = Cache.instance.kingwar.sArenaInfo.processDt[EArenaProcess._EArenaFinalMatch2];
                if (loc6 && loc7) 
                {
                    loc12 = loc6.getMonth() + 1;
                    loc13 = loc6.getDate();
                    loc14 = loc7.getMonth() + 1;
                    loc15 = loc7.getDate();
                    this._txIV.htmlText = Language.getStringByParam(70421, loc12, loc13, loc14, loc15);
                }
                else 
                {
                    this._txIV.htmlText = "";
                }
            }
            return;
        }

        /* internal  */updateProgress(): void
        {
            return;
        }

        /* internal  */updateImages(): void
        {
            var loc1=ClockManager.instance.nowDate.getTime();
            if (this._isOpen) 
            {
                if (this._myProcess < this._syProcess) 
                {
                    this._sbmUp.visible = true;
                    this._sbmUp.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_noRise);
                }
                else 
                {
                    this._sbmUp.visible = false;
                }
            }
            else if (this._syProcess != -1) 
            {
                if (this._myProcess <= this._syProcess && !(this._syProcess === -1)) 
                {
                    this._sbmUp.visible = true;
                    this._sbmUp.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_noRise);
                }
                else 
                {
                    this._sbmUp.visible = true;
                    this._sbmUp.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_youRise);
                }
            }
            else 
            {
                this._sbmUp.visible = false;
            }
            this._sbmMid2.bitmapData = this.getShowBm(EArenaProcess._EArenaElimination1, EArenaProcess._EArenaGroupMatch1, this._myProcess, this._syProcess);
            this._sbmMid3.bitmapData = this.getShowBm(EArenaProcess._EArenaGroupMatch1, EArenaProcess._EArenaFinalMatch1, this._myProcess, this._syProcess);
            this._sbmMid4.bitmapData = this.getShowBm(EArenaProcess._EArenaFinalMatch1, EArenaProcess._EArenaFinalMatch2, this._myProcess, this._syProcess);
            return;
        }

        /* internal  */getShowBm(arg1: int, arg2: int, arg3: int, arg4: int): Object /* flash.display.BitmapData */
        {
            if (arg1 > arg4) 
            {
                return GlobalClass.getBitmapData(ImagesConst.kingWar_close);
            }
            if (arg2 <= arg3) 
            {
                return GlobalClass.getBitmapData(ImagesConst.kingWar_rise);
            }
            return GlobalClass.getBitmapData(ImagesConst.kingWar_noRise2);
        }

        protected onSignUpTxClick(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=ClockManager.instance.nowDate.getTime();
            if (Cache.instance.role.entityInfo.level < 60) 
            {
                MsgManager.showRollTipsMsg(Language.getString(70431));
                return;
            }
            if (Cache.instance.kingwar.sArenaInfo.processDt[0].getTime() <= loc1 && loc1 <= Cache.instance.kingwar.sArenaInfo.processDt[1].getTime()) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarSignUp));
            }
            else if (loc1 > Cache.instance.kingwar.sArenaInfo.processDt[1].getTime()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(70440));
            }
            else if (loc1 < Cache.instance.kingwar.sArenaInfo.processDt[0].getTime()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(70441));
            }
            return;
        }

        /* internal  */initView(): void
        {
            this._curTimeTx = ObjCreate.createTextField("", 15, 12, 160, 22, this, new GTextFormat(null, 14, 11661311));
            ObjCreate.createBg(0, 38, 802, 444, this);
            this._kingGetReward = ObjCreate.createGLoadedButton(ResFileConst.KingGetRewardBtn, 676, 375, 110, 30, this);
            var loc1=ObjCreate.createTextField(Language.getString(70423) + ":", 211, 14, 108, 23, this, GlobalStyle.textFormat6);
            this._txCurProcess = ObjCreate.createTextField("", 296, 14, 108, 23, this, GlobalStyle.textFormat6);
            this._sbmUp = ObjCreate.createBitmap("", 532, 11, this);
            this._sbmUp.visible = false;
            this._skipDecTx = ObjCreate.createTextField("", 668, 414, 120, 20, this);
            this._skipDecTx.htmlText = Language.getString(70408);
            this._skipDecTx.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._skipDecTx.addEventListener(flash.events.TextEvent.LINK, this.onTxClickHandler);
            this._checkRuleTx = ObjCreate.createTextField("", 668, 436, 120, 20, this);
            this._checkRuleTx.htmlText = Language.getString(70424);
            this._checkRuleTx.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._checkRuleTx.addEventListener(flash.events.TextEvent.LINK, this.onTxClickHandler);
            var loc2=0;
            while (loc2 < 4) 
            {
                this._dateTip = new DateTipSp();
                this._dateTip.x = 37 + loc2 * 216;
                this._dateTip.y = 64;
                addChild(this._dateTip);
                this._dateTipArr.push(this._dateTip);
                ++loc2;
            }
            this._progressBar = new KingwarTimeProgress();
            this._progressBar.move(30, 96);
            this._progressBar.progressBarClass = ImagesConst.ProgressInner;
            this._progressBar.isHaveProgressPoint(true);
            this._progressBar.setValue(10, 100);
            addChild(this._progressBar);
            this._sbmArrowII = ObjCreate.createBitmap("", 50, 126, this);
            this._sbmArrowIII = ObjCreate.createBitmap("", 285, 126, this);
            this._sbmArrowIV = ObjCreate.createBitmap("", 495, 126, this);
            this._sbmArrowV = ObjCreate.createBitmap("", 705, 126, this);
            this._sbmMid2 = ObjCreate.createBitmap("", 125, 194, this);
            this._sbmMid3 = ObjCreate.createBitmap("", 370, 216, this);
            this._sbmMid4 = ObjCreate.createBitmap("", 576, 231, this);
            var loc3=ObjCreate.createBg(19, 268, 96, 20, this, ImagesConst.FightingStrgBg);
            var loc4=ObjCreate.createBg(258, 297, 96, 20, this, ImagesConst.FightingStrgBg);
            var loc5=ObjCreate.createBg(449, 332, 128, 20, this, ImagesConst.FightingStrgBg);
            var loc6;
            (loc6 = new GTextFormat()).align = flash.text.TextFormatAlign.CENTER;
            loc6.color = GlobalStyle.color2Uint;
            var loc7=ObjCreate.createTextField(Language.getString(70415), 13, 269, 106, 20, this, loc6);
            var loc8=ObjCreate.createTextField(Language.getString(70416), 250, 298, 106, 20, this, loc6);
            var loc9=ObjCreate.createTextField(Language.getString(70417), 454, 331, 106, 20, this, loc6);
            var loc10;
            loc9.filters = loc10 = [FilterConst.glowFilter];
            loc8.filters = loc10 = loc10;
            loc7.filters = loc10;
            this._txII = ObjCreate.createTextField("", 21, 290, 140, 185, this);
            this._txIII = ObjCreate.createTextField("", 252, 320, 120, 185, this);
            this._txIV = ObjCreate.createTextField("", 461, 355, 120, 185, this);
            this._txIV.wordWrap = loc10 = true;
            this._txIII.wordWrap = loc10 = loc10;
            this._txII.wordWrap = loc10;
            this._txIV.multiline = loc10 = true;
            this._txIII.multiline = loc10 = loc10;
            this._txII.multiline = loc10;
            LoaderHelp.addResCallBack(ResFileConst.kingWar, this.onLoadBmResource);
            this.updateInfo();
            return;
        }

        /* internal */ /* var */_curTimeTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_txCurProcess: Object /* flash.text.TextField */;

        /* internal */ /* var */_kingGetReward: GLoadedButton;

        /* internal */ /* var */_skipDecTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_checkRuleTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_progressBar: KingwarTimeProgress;

        /* internal */ /* var */_dateTip: DateTipSp;

        /* internal */ /* var */_dateTipArr: Array<any>;

        /* internal */ /* var */_sbmArrowII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmArrowIII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmArrowIV: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmArrowV: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmMid2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmMid3: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmMid4: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmUp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isOpen: Boolean;

        /* internal */ /* var */_nowData: Date;

        /* internal */ /* var */str: string;

        /* internal */ /* var */_txII: Object /* flash.text.TextField */;

        /* internal */ /* var */_txIII: Object /* flash.text.TextField */;

        /* internal */ /* var */_txIV: Object /* flash.text.TextField */;

        /* internal */ /* var */_syProcess: int;

        /* internal */ /* var */_myProcess: int;
    }
